<!DOCTYPE html>
<title>Test document user gesture autoplay policy across navigation</title>
<script src="/js-test-resources/js-test.js"></script>
<script>
var jsTestIsAsync = true;
let results = {};

function tearDown() {
  internals.settings.setAutoplayPolicy('no-user-gesture-required');

  shouldBeUndefined(results.media);
  shouldBeEqualToString('results.webAudio', 'running');

  finishJSTest();
}

function runMediaTests() {
  return new Promise(resolve => {
    const video = document.createElement('video');
    video.src = "/resources/test.ogv";
    video.play().then(result => { results.media = result },
                      result => { results.media = result })
                .then(resolve);
  });
}

function runWebAudioTests() {
  const audioContext = new AudioContext();
  results.webAudio = audioContext.state;
}

async function runTests() {
  await runMediaTests();
  runWebAudioTests();
}

window.addEventListener('load', async function() {
  if (window.testRunner) {
    testRunner.dumpAsText();
    await runTests();
    testRunner.dumpBackForwardList();
    tearDown();
  }
}, false);
</script>
<body>
</body>
